﻿using Autofac;
using CleanLite.Domain.Interfaces;
using CleanLite.Infrastructure;
using CleanLite.Shared.Configuration;
using System.Reflection;

namespace CleanLite.Web.Module
{
    public class AutofacModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var registerAssemblys = ConfigurationService.GetStringList("RegisterAssemblys");
            var assemblys = registerAssemblys.Select(Assembly.Load).ToArray();

            builder.RegisterGeneric(typeof(BaseRepository<>))
                .As(typeof(IBaseRepository<>))
                .InstancePerDependency();

            foreach (var assembly in assemblys)
            {
                builder.RegisterAssemblyTypes(assembly)
                  .AsImplementedInterfaces()
                  .AsSelf()
                  .InstancePerDependency()
                  .PropertiesAutowired();
            }
        }
    }
}